//this is a clock that is circlr
//port java.io.*;
import java.applet.Applet;
import java.awt.Graphics;
import java.util.Calendar;
import java.awt.Color;
import java.awt.Font;
public class Clock extends Applet implements Runnable
{
	private Color[] color;
	private final int RADIUS=200;
	private final int CENTER_X=RADIUS*2;
	private final int CENTER_Y=RADIUS*2;
	private final double GRADUATION_L=RADIUS*0.9;
	private final double HOUR_L = RADIUS * 0.4;
	private final double MINUTE_L =RADIUS * 0.6;
	private final double SECOND_L =RADIUS * 0.8;
	private final int RATIO=60;
	private final int MAX=12;
	private int count=0;
	private int hour;
	private int minute;
	private int second;
	private Thread thread;
	private Font font;
	//Thread thread;
	private Calendar cal;
	//public  Graphics gr=getGraphics();
        public void init()
                {
					
					color = new Color[MAX];
					color[0] = Color.BLACK;
					color[1] = Color.WHITE;
					color[2] = Color.BLUE;
					color[3] = Color.YELLOW;
					color[4] = Color.RED;
					color[5] = Color.GREEN;
					color[6] = Color.GRAY;
					color[7] = Color.PINK;
					color[8] = Color.ORANGE;
					color[9] = Color.CYAN;
					color[10] = Color.DARK_GRAY;
					color[11] = Color.MAGENTA;
             		thread=new Thread(this);
                }
	public void  start()
		{
			//thread.start();
		}
	public int  getSecond()
		{
			cal=Calendar.getInstance();
			second=cal.get(Calendar.SECOND);
			return second;
		}
	public int getMinute()
		{
			cal=Calendar.getInstance();
			minute=cal.get(Calendar.MINUTE);
			return minute;
		}
	public int getHour()
		{
			
			cal=Calendar.getInstance();
			hour=cal.get(Calendar.HOUR);
			return hour;
		}
	public void drawMinute(Graphics g)
		{		
				
				double stemp=getMinute()+getSecond()*1.0/RATIO; 
				int x=(int) (CENTER_X+MINUTE_L*Math.sin(stemp*StrictMath.PI*2.0/RATIO));
				int y=(int )(CENTER_Y-MINUTE_L*Math.cos(stemp*StrictMath.PI*2.0/RATIO));
				g.setColor(Color.RED);
				g.drawLine(CENTER_X,CENTER_Y,x,y);
		}
	public void drawHour(Graphics g)
		{
				double stemp=getHour()+getMinute()*1.0/RATIO; 
				int x=(int) (CENTER_X+HOUR_L*Math.sin(stemp*StrictMath.PI/6));
				int y=(int )(CENTER_Y-HOUR_L*Math.cos(stemp*StrictMath.PI/6));
				g.setColor(Color.BLUE);
				g.drawLine(CENTER_X,CENTER_Y,x,y);
				
		}
	public void drawSecond(Graphics g)
	{
		double stemp = getSecond();
		int x = (int)(CENTER_X+ SECOND_L * Math.sin(stemp * StrictMath.PI*2/ RATIO));
		int y = (int)(CENTER_Y- SECOND_L * Math.cos(stemp * StrictMath.PI *2/ RATIO));
		g.setColor(Color.YELLOW);
		g.drawLine(CENTER_X,CENTER_Y,x,y);

	}
	
	public void drawGra(Graphics g)
	{
		int x;
		int y;
		int a;
		int b;
		//Integer in;
		String str; 
		for (int i = 1; i <=12; i++)
		{
			
			str=Integer.toString(i);
			x=(int)(CENTER_X+GRADUATION_L*Math.sin (StrictMath.PI/6*i));
			y=(int)(CENTER_Y-GRADUATION_L*Math.cos(StrictMath.PI/6*i));
			a=(int)(CENTER_X+RADIUS*Math.sin(StrictMath.PI/6*i));
			b=(int)(CENTER_Y-RADIUS*Math.cos(StrictMath.PI/6*i));
			g.setColor(Color.BLUE);
			g.drawLine(x,y,a,b);
			g.setColor(color[(i+count)%12]);
			g.setFont(new Font("",Font.ITALIC|Font.BOLD,20));
			System.out.println(color[(i+count)%12]);
			g.drawString(str,x-2,y+2);
		}
	}

	public void update(Graphics g)
		{
		
			g.setColor(Color.WHITE);
			g.fillRect(0,0,CENTER_X*2*2,CENTER_X*2);
			
			paint(g);
		}
	public void paint(Graphics g)
         {


				font = g.getFont();
				g.setColor(Color.GREEN);
				g.drawArc(CENTER_X-RADIUS,CENTER_Y-RADIUS,RADIUS*2,RADIUS*2,0,360);
				g.setColor(Color.BLACK);
				g.setFont(new Font("",Font.ITALIC,30));
				g.drawString(""+getHour()+":"+getMinute()+":"+getSecond(),CENTER_X,CENTER_Y*2);
				g.setFont(font);
				drawSecond(g);
				drawMinute(g);
				drawHour(g);
				drawGra(g);
				thread.start();
                     //repaint();
       };//end of paint
       public void run()
       	{

       		while(true)
       			{
					count++;
       				repaint();
					try
					{
					Thread.sleep(500);
					}
					catch(Exception e)
					{e.printStackTrace();}
       			}
       	}
}
/*
<applet code="Clock.class" height =500 width =400>
</applet>*/